#include "config.h"

#include "ms2lstat.h"

#define N_STATUSES	7

static ecm_uint32	n_requests;

static ecm_uint32	n_status[N_STATUSES];
static ecm_uint32	n_status_others;

static ecm_uint32	status_code[] = {
	200, 400, 401, 404, 408, 480, 500
};

void
update_request(lent_t *lent)
{
	n_requests++;

	switch (lent->status) {
	case 200:
		n_status[0]++;
		break;
	case 400:
		n_status[1]++;
		break;
	case 401:
		n_status[2]++;
		break;
	case 404:
		n_status[3]++;
		break;
	case 408:
		n_status[4]++;
		break;
	case 480:
		n_status[5]++;
		break;
	case 500:
		n_status[6]++;
		break;
	default:
		n_status_others++;
		ERR("session status is %u", lent->status);
		break;
	}
}

void
report_request_result(FILE *fp)
{
	FILE	*fp_req = setup_logging("reqstatus");
	ecm_uint32	i;

	ecm_fprintf(fp, "Total Number of Requests:           %u\n", n_requests);

	ecm_fprintf(fp_req, "# status count\n");
	for (i = 0; i < N_STATUSES; i++)
		ecm_fprintf(fp_req, "%3u %6u\n", status_code[i], n_status[i]);
	ecm_fprintf(fp_req, "-   %6u\n", n_status_others);

	ecm_fclose(fp_req);
}
